
#include "ShapeManager.h"
#include "Circle.h"
#include "Rectangle.h"

std::map<std::string, Shape*> ShapeManager::shape_map_
    {
        std::pair<std::string, Shape*>("CIR", new Circle()),
        std::pair<std::string, Shape*>("REC", new Rectangle())
    };

Shape* ShapeManager::get_shape(const std::string& type)
{
  Shape* p = get_prototype(type);
  return p ? p->Clone() : nullptr;
}

Shape* ShapeManager::get_prototype(const std::string& type)
{
  auto kv = shape_map_.find(type);
  return kv == shape_map_.end() ? nullptr : kv->second;
}

ShapeManager::~ShapeManager()
{
  for (auto kv : shape_map_) {
    delete kv.second;
    kv.second = nullptr;
  }

  shape_map_.clear();
}
